package com.okex.open.api;

import com.alibaba.fastjson.JSONObject;
import com.okex.open.api.bean.trade.param.*;
import com.okex.open.api.config.APIConfiguration;
import com.okex.open.api.service.trade.TradeAPIService;
import com.okex.open.api.service.trade.impl.TradeAPIServiceImpl;
import com.okex.open.api.utils.DateUtils;
import com.okex.open.api.utils.DateUtils1;

import java.util.concurrent.TimeUnit;


public class TradeAPITest extends TradeAPIBaseTest {
    private static TradeAPIService tradeAPIService;
    public static String SZBUY = "800";//买入资金量 usdt
    public static String symbol = "SUI-USDT";
    private static APIConfiguration config;
    public void before() {
        config = config();
        tradeAPIService = new TradeAPIServiceImpl(config);
    }
    /**
     * 下单 Place Order 买
     * POST /api/v5/trade/order
     */
    public static void placeOrderBuy(){
        PlaceOrder placeOrder =new PlaceOrder();
        placeOrder.setInstId(symbol);
        placeOrder.setTdMode("cash");
        placeOrder.setSide("buy");
        placeOrder.setOrdType("market");
        placeOrder.setSz(SZBUY);
        JSONObject jsonObject = tradeAPIService.placeOrder(placeOrder);
        System.out.println(DateUtils1.dateTimeNow()+":"+jsonObject);
    }

    /**
     * 下单 Place Order 买
     * POST /api/v5/trade/order
     */
    public static void keepplaceOrderBuy(long preoidTime){
        JSONObject jsonObject = null;
        PlaceOrder placeOrder =new PlaceOrder();
        placeOrder.setInstId(symbol);
        placeOrder.setTdMode("cash");
        placeOrder.setSide("buy");
        placeOrder.setOrdType("market");
        placeOrder.setSz(SZBUY);
        while (true){
            jsonObject = tradeAPIService.placeOrder(placeOrder);
            System.out.println(DateUtils1.dateTimeNow()+":"+jsonObject);
            try {
                TimeUnit.MILLISECONDS.sleep(preoidTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
